package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;

import com.ruoyi.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.ProspectsStudent;
import com.ruoyi.system.service.IProspectsStudentService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 潜在学员Controller
 * 
 * @author tong
 * @date 2024-01-23
 */
@RestController
@RequestMapping("/student")
public class ProspectsStudentController extends BaseController
{
    @Autowired
    private IProspectsStudentService prospectsStudentService;

    /**
     * 查询潜在学员列表
     */
    @RequiresPermissions("system:student:list")
    @GetMapping("/list")
    public TableDataInfo list(ProspectsStudent prospectsStudent)
    {
        startPage();
        List<ProspectsStudent> list = prospectsStudentService.selectProspectsStudentList(prospectsStudent);
        return getDataTable(list);
    }

    /**
     * 导出潜在学员列表
     */
    @RequiresPermissions("system:student:export")
    @Log(title = "潜在学员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProspectsStudent prospectsStudent)
    {
        List<ProspectsStudent> list = prospectsStudentService.selectProspectsStudentList(prospectsStudent);
        ExcelUtil<ProspectsStudent> util = new ExcelUtil<ProspectsStudent>(ProspectsStudent.class);
        util.exportExcel(response, list, "潜在学员数据");
    }

    /**
     * 获取潜在学员详细信息
     */
    @RequiresPermissions("system:student:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(prospectsStudentService.selectProspectsStudentById(id));
    }

    /**
     * 新增潜在学员
     */
    @RequiresPermissions("system:student:add")
    @Log(title = "潜在学员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProspectsStudent prospectsStudent)
    {
        return toAjax(prospectsStudentService.insertProspectsStudent(prospectsStudent));
    }

    /**
     * 修改潜在学员
     */
    @RequiresPermissions("system:student:edit")
    @Log(title = "潜在学员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProspectsStudent prospectsStudent)
    {
        return toAjax(prospectsStudentService.updateProspectsStudent(prospectsStudent));
    }

    /**
     * 删除潜在学员
     */
    @RequiresPermissions("system:student:remove")
    @Log(title = "潜在学员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(prospectsStudentService.deleteProspectsStudentByIds(ids));
    }

    /**
     * 接管潜在学员
     */
    @GetMapping(value = "/takeOverStudent/{id}")
    public R takeOverStudent(@PathVariable("id") @NotEmpty(message = "ID不能为空") Long id)
    {
        prospectsStudentService.takeOverStudent(id);
        return R.ok();
    }


    /**
     * 放弃潜在学员
     */
    @GetMapping(value = "/abandonStudent/{id}")
    public R abandonStudent(@PathVariable("id")  @NotEmpty(message = "ID不能为空") Long id)
    {
        prospectsStudentService.abandonStudent(id);
        return R.ok();
    }


}
